<template>
	<view>
		<view style="padding: 20rpx;">
			<view style="display: flex;width: 100%;">
				<view style="width: 600rpx;" @click="goinfo">
					<view class="hide" style="font-weight: 500;font-size: 32rpx;color: rgba(0, 0, 0, 0.6);">
						<text>{{name}}</text>
					</view>
					<view style="margin-top: 10rpx;color: #8d8d8d;">
						<text class="hide">{{address}}</text>
					</view>
				</view>
				<!-- <view class="sx">

				</view> -->
				<view style="margin-left: 35rpx;">
					<view @click="gomap">
						<u-icon name="map" size="50" color="#40A9FF"></u-icon>
						<view class="">
							<text style="color: rgba(0,0,0,0.5);">地图</text>
						</view>
					</view>
				</view>

			</view>
		</view>
		<view v-if="infoshow" style="align-items: center;">
			<helang-blur :params="params"></helang-blur>

			<view style="position: absolute;z-index: 99;height: 400rpx;width: 100%;margin-top: -280rpx;">
				<u-swiper name="smallPhoto" :current="current" @click="clickimg" bg-color="rgba(0, 0, 0, 0.0)"
					:height="260" :list="movies" img-mode="scaleToFill" mode="none" :effect3d="true"
					:effect3d-previous-margin="280" :autoplay="false" :circular="false" @change="change"
					border-radius="0" @touchstart="touchstart" @touchend="touchend" @touchcancel ="touchend"></u-swiper>
			</view>
			<view class="cssk" v-if="bkshow">

			</view>
			<view class="cssshape">

			</view>
			<view class="infoa" style="margin-top: 15rpx;">
				<text style="font-size: 36rpx;font-weight: 500;">{{infos.name}}</text>
				<text v-if="infos.grade>0"
					style="color: #ec8200;font-weight: 700;margin-left: 10rpx;font-size: 28rpx;">{{infos.grade}}</text>
				<text v-if="infos.grade>0" style="color: #ec8200;font-weight: 400;font-size: 24rpx;">分</text>
			</view>
			<view class="infoa " style="margin-top: 10rpx;margin-bottom: 25rpx;opacity: 0.5;">
				<text style="color: #000000;">{{infos.duration}}|</text>
				<text style="color: #000000;">{{infos.genre}}</text>
				
			</view>
			<view class="hide" style="opacity: 0.5;width: 100%;text-align: center;margin-top: -30rpx;">
				<text v-if="infos.mainPerformer !== ''"
					style="color: #000000;">{{infos.mainPerformer}}</text>
			</view>
		</view>
		<u-gap height="20" bg-color="#FFFFFF"></u-gap>
		<u-line />
		
		<u-tabs :bar-width="50" active-color="#EA5344" :list="list" :is-scroll="true" :current="currents"
			@change="changes"></u-tabs>
		<u-line />
		<view style="padding: 20rpx;">
			<view v-if="moviejh.length>0" style="margin-bottom: 20rpx;" v-for="(item,index) in moviejh" :key="index">
				<view style="display: flex;">
					<view style="width: 200rpx;text-align: left;margin-left: 5rpx;">
						<view class="">
							<text style="font-size: 42rpx;font-weight: 500;">{{item.time}}</text>
						</view>
						<view class="">
							<text style="font-size: 26rpx;font-weight: 400;opacity: 0.5;">{{item.endtime}}散场</text>
						</view>
					</view>
					<view
						style="width: 300rpx;text-align: center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">
						<view style="margin-top: 10rpx;">
							<text
								style="font-size: 30rpx;font-weight: 500;color: rgba(0,0,0,0.7);">{{item.language}}{{item.dimensional}}</text>
						</view>
						<view style="margin-top: 10rpx;">
							<text
								style="font-size: 26rpx;font-weight: 400;opacity: 0.5;">{{item.hallName | getstringleft}}</text>
						</view>
					</view>
					<view style="width: 200rpx;text-align: right;margin-top: 15rpx;">
						<view class="">
							<text style="font-size: 40rpx;font-weight: 500;color:#EA5344;">{{item.uprice}}</text>
							<text style="font-size: 24rpx;font-weight: 500;color:#EA5344;">元</text>
						</view>
					</view>
					<view style="width: 200rpx;">
						<view style="align-items: right;margin-top: 10rpx;margin-right: 10rpx;">
							<view v-if="item.canbuy === 1">
								<button hover-class="none" type="default"  
									style="width: 120rpx;height: 60rpx;background-color: #EA5344;color: #FFFFFF;font-size: 24rpx;"
									@click="goseat(item)">购票
								</button>
							</view>
							<view v-if="item.canbuy === 0">
								<button  hover-class="none"
									style="width: 120rpx;height: 60rpx;background-color: #d4d4d4;color: #5d5d5d;font-size: 24rpx;">停售
								</button>
							</view>

						</view>
					</view>
				</view>
				<u-line color="#d5d5d5" margin="15rpx 0rpx" />

			</view>

			<u-empty icon-size="280" margin-top="100" font-size="30" v-if="nullshow" text="该影院暂无排片"
				src="/static/images/yy.png"></u-empty>
		</view>
		<aui-loading ref="auiLoading" :type="auiLoading.type" :direction="auiLoading.row" :msg="auiLoading.msg"
			:mask="auiLoading.mask"></aui-loading>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import Config from '../../common/config.js';
	import helangBlur from "@/components/helang-blur/helang-blur.vue"
	import {
		aui
	} from '@/components/aui-loading/common/aui/js/aui.js';
	import auiLoading from '@/components/aui-loading/aui-loading.vue';
	export default {
		components: {
			helangBlur,
			auiLoading
		},
		data() {
			return {
				duration:"",
				nullshow: false,
				auiLoading: {
					show: false,
					type: 3,
					direction: 'row',
					msg: '加载中',
					mask: true,
				},
				getphoneshow: false,
				list: [],
				currents: 0,
				infoshow: true,
				bkshow: true,
				infos: {},
				params: {
					width: '100%',
					height: '300rpx',
					image: "",
					blur: "s"
				},
				current: 0,
				id: 0,
				name: '',
				address: '',
				coord: '',
				movies: [],
				moviejh: [],
				filmId: "",

			}
		},
		onPullDownRefresh() {
			this.list=[]
			this.movies=[]
			this.moviejh=[]
			this.current=0
			this.getmovie()
		
		},
		onLoad(parmar) {

			if (parmar.filmId != undefined && parmar.filmId != '') {
				this.filmId = parmar.filmId;
			}

			this.id = parmar.Id;
			this.name = parmar.name;
			this.address = parmar.address;
			this.coord = parmar.coord;
			// uni.setNavigationBarTitle({
			// 	title: parmar.name
			// })

			this.getmovie()


		},
		filters: {
			getstringleft: function(value) {
				let a = value.indexOf('厅')
				if (a != -1) {
					return value.substr(0, a + 1)
				} else {
					return value
				}
			}
		},
		computed: {

		},
		methods: {
			touchstart(){
				this.bkshow = false
			},
			touchend(){
				setTimeout(function() {
					// 这里就是处理的事件
					this.bkshow = true;
				}, 430);
			},
			canbuy(time) {
				//获取当前时间
				var currentTime = new Date().getTime();
				var customTime = time.toString();
				customTime = customTime.replace(/-/g, "/"); //替换字符，变成标准格式  
				customTime = Date.parse(new Date(customTime));
				let tmpa = customTime-currentTime
				tmpa=tmpa/60000
				if (tmpa>=20) {
					return 1
				} else {
					return 0
				}
			},
			islogin() {

			},
			goseat(item) {
				let that = this;
				that.$refs.auiLoading.show();
				uni.request({
					url: Config.ServerIP + '/uaa/auth/refresh',
					method: "POST",
					header: {
						Authorization: 'Bearer ' + Config.token
					},
					success: (resd) => {
						that.$refs.auiLoading.hide();
						if (resd.data.code == 401) {
							let path = '/pages/cinemainfo/cinemainfo?Id=' + that.id + '&name=' + that.name +
								'&address=' + that.address + '&coord=' + that.coord + '&filmId=' + that.filmId
							path = encodeURIComponent(path)
							that.$refs.auiLoading.hide();
							uni.redirectTo({
								url: '../login/login?path=' + path
							})
							return
						}
						let info={
							'time':that.list[that.currents].name+' '+item.time+'-'+item.endtime,
							'cinema':that.name
						}
						
						uni.setStorageSync('confirminfo',info)
						uni.navigateTo({
							url: '/pages/selectseat/selectseat?cinemaId=' +
								item
								.cinemaId +
								'&hallId=' +
								item
								.hallId +
								'&showIndex=' +
								item
								.showIndex +
								'&hallName=' +
								item
								.hallName +
								'&filmName=' +
								item
								.filmName +
								'&language=' +
								item
								.language +
								'&showTime=' +
								item
								.showTime +
								'&cprice=' +
								item
								.uprice +
								"&smallPhoto=" +
								that
								.movies[
									that
									.current
								]
								.smallPhoto +
								"&filmId=" +
								that
								.filmId +
								'&cinemaId=' +
								that
								.id +
								'&cinemaName=' +
								that
								.name+
								'&duration='+that
								.movies[
									that
									.current
								].duration
						});
					},
					fail() {
						let path = '/pages/cinemainfo/cinemainfo?Id=' + that.id + '&name=' + that.name +
							'&address=' + that.address + '&coord=' + that.coord + '&filmId=' + that.filmId
						path = encodeURIComponent(path)
						that.$refs.auiLoading.hide();
						uni.redirectTo({
							url: '../login/login?path=' + path
						})
						return
					}
				})
			},
			goinfo() {
				uni.navigateTo({
					url: '/pages/cinemaadds/cinemaadds?id=' + this.id
				});
			},
			gomap() {
				let coordS = this.coord;
				let that = this;
				let tmpc = coordS.split(',')
				that.longitude = tmpc[0]
				that.latitude = tmpc[1]
				uni.openLocation({
					latitude: parseFloat(that.latitude),
					longitude: parseFloat(that.longitude),
					name: that.name,
					address: that.address,
					scale: 18,
					fail: function(res) {

					}
				})
			},
			addDate(date, days) {
				var d = new Date(date);
				d.setDate(d.getDate() + days);
				return d;
			},
			getjh(key) {
				let that = this;
				uni.request({
					url: Config.ServerIP + "/movie/app/movie/filmShowCinema/session/list",
					method: "POST",
					data: {
						cinemaId: that.id + '',
						direction: "asc",
						filmId: that.infos.filmId,
						pageNum: 1,
						pageSize: 30,
						showTime: key
					},
					success: (res) => {
						if (res.data.code != 200) {
							that.$refs.uToast.show({
								title: '获取信息错误',
								type: 'error'
							})
							return
						}

						//that.moviejh = res.data.data
						let tmpdata = res.data.data
						let movielong = that.infos.duration.replace(/分钟/g, "")
						if (tmpdata.length <= 0) {
							that.nullshow = true
						} else {
							that.nullshow = false
						}
						for (var i = 0; i < tmpdata.length; i++) {
							let a = that.formatesj(movielong, tmpdata[i].showTime)
							tmpdata[i].time = a.startTime
							tmpdata[i].endtime = a.endTime
							tmpdata[i]['canbuy'] = that.canbuy(tmpdata[i].showTime)
							that.moviejh.push(tmpdata[i])
						}
					},
					fail: (res) => {}

				})
			},
			ishave(time) {
				let that = this;
				let k = false;
				let req = {
					cinemaId: that.id + '',
					direction: "asc",
					filmId: that.infos.filmId,
					pageNum: 1,
					pageSize: 1,
					showTime: time
				}
				this.$api.myRequest({
					url: '/movie/app/movie/filmShowCinema/session/list',
					methods: 'POST',
					data: req
				}).then(res => {
					if (res.data.data.length > 0) {
						k = true
					} else {
						k = false
					}
				})
				return k
			},
			formatesj(timelong, times) {
				let hours = times.split(" ")[1].split(":")[0]
				let mins = times.split(" ")[1].split(":")[1]
				let startTime = hours + ":" + mins
				let tmphours = parseInt(timelong / 60) + parseInt(hours)
				let tmpmins = timelong % 60 + parseInt(mins)
				if (tmpmins >= 60) {
					tmphours++
					tmpmins = tmpmins - 60
				}
				if (tmphours >= 24) {
					tmphours = tmphours - 24
				}
				if (tmpmins < 10) {
					tmpmins = '0' + tmpmins
				}
				if (tmphours < 10) {
					tmphours = '0' + tmphours
				}
				let endTime = tmphours + ":" + tmpmins
				let a = {
					startTime: startTime,
					endTime: endTime
				}
				return a;
			},
			initdata() {

				let that = this;
				that.moviejh = []
				that.$refs.auiLoading.show();
				var myDate = new Date();
				var weekName = new Array("周日", "周一", "周二", "周三", "周四", "周五", "周六");
				let todayText = "今天" + (myDate.getMonth() + 1) + "月" + myDate.getDate() + "日";
				let a = {
					name: todayText,
					key: myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate() +
						" 00:00:00"
				}
				let req = {
					cinemaId: that.id + '',
					direction: "asc",
					filmId: that.infos.filmId,
					pageNum: 1,
					pageSize: 1,
					showTime: a.key

				}
				that.$api.myRequest({
					url: '/movie/app/movie/filmShowCinema/session/list',
					methods: 'POST',
					data: req
				}).then(res => {
					if (res.data.data.length > 0) {
						that.getjh(a.key);
						that.list.push(a)
					}
				}).then(a => {
					let tmpdata = that.addDate(myDate, 1)
					let tomorrowText = "明天" + (tmpdata.getMonth() + 1) + "月" + tmpdata.getDate() + "日";
					a = {
						name: tomorrowText,
						key: tmpdata.getFullYear() + "-" + (tmpdata.getMonth() + 1) + "-" + tmpdata.getDate() +
							" 00:00:00"
					}
					req = {
						cinemaId: that.id + '',
						direction: "asc",
						filmId: that.infos.filmId,
						pageNum: 1,
						pageSize: 1,
						showTime: a.key

					}
					that.$api.myRequest({
						url: '/movie/app/movie/filmShowCinema/session/list',
						methods: 'POST',
						data: req
					}).then(res => {
						if (res.data.data.length > 0) {
							if (that.list.length == 0) {
								that.getjh(a.key);
							}
							that.list.push(a)
						}
					}).then(a => {
						tmpdata = this.addDate(myDate, 2);
						let htText = "后天" + (tmpdata.getMonth() + 1) + "月" + tmpdata.getDate() + "日";
						a = {
							name: htText,
							key: tmpdata.getFullYear() + "-" + (tmpdata.getMonth() + 1) + "-" + tmpdata
								.getDate() +
								" 00:00:00"
						}
						req = {
							cinemaId: that.id + '',
							direction: "asc",
							filmId: that.infos.filmId,
							pageNum: 1,
							pageSize: 1,
							showTime: a.key
						}
						that.$api.myRequest({
							url: '/movie/app/movie/filmShowCinema/session/list',
							methods: 'POST',
							data: req
						}).then(res => {
							if (res.data.data.length > 0) {
								if (that.list.length == 0) {
									that.getjh(a.key);
								}
								that.list.push(a)
							}
						}).then(a => {
							tmpdata = this.addDate(myDate, 3);
							let fordatText = weekName[tmpdata.getDay()] + (tmpdata.getMonth() +
									1) + "月" + tmpdata.getDate() +
								"日";
							a = {
								name: fordatText,
								key: tmpdata.getFullYear() + "-" + (tmpdata.getMonth() + 1) +
									"-" + tmpdata.getDate() +
									" 00:00:00"
							}
							req = {
								cinemaId: that.id + '',
								direction: "asc",
								filmId: that.infos.filmId,
								pageNum: 1,
								pageSize: 1,
								showTime: a.key
							}
							that.$api.myRequest({
								url: '/movie/app/movie/filmShowCinema/session/list',
								methods: 'POST',
								data: req
							}).then(res => {
								if (res.data.data.length > 0) {
									if (that.list.length == 0) {
										that.getjh(a.key);
									}
									that.list.push(a)
								}
							}).then(a => {
								tmpdata = this.addDate(myDate, 4);
								let fivedatText = weekName[tmpdata.getDay()] + (tmpdata
										.getMonth() + 1) + "月" + tmpdata.getDate() +
									"日";
								a = {
									name: fivedatText,
									key: tmpdata.getFullYear() + "-" + (tmpdata
											.getMonth() + 1) + "-" + tmpdata
										.getDate() +
										" 00:00:00"
								}
								req = {
									cinemaId: that.id + '',
									direction: "asc",
									filmId: that.infos.filmId,
									pageNum: 1,
									pageSize: 1,
									showTime: a.key

								}
								that.$api.myRequest({
									url: '/movie/app/movie/filmShowCinema/session/list',
									methods: 'POST',
									data: req
								}).then(res => {
									if (res.data.data.length > 0) {
										if (that.list.length == 0) {
											that.getjh(a.key);
										}
										that.list.push(a)
									}
								}).then(a => {
									if (that.list.length <= 0) {
										that.nullshow = true
									} else {
										that.nullshow = false
									}
									that.$refs.auiLoading.hide();
								})
							})
						})
					})
				})
			},
			changes(index) {
				this.currents = index;
				this.moviejh = []
				this.getjh(this.list[index].key);
			},
			getmovie() {
				let that = this;
				uni.request({
					url: Config.ServerIP + "/movie/app/movie/filmShowCinema/film/list",
					method: "POST",
					data: {
						cinemaId: that.id + '',
						cityId: Config.loaction.cityId,
						direction: "asc",
						pageNum: "1",
						pageSize: '50',
					},
					success: (res) => {
						if (res.data.code != 200) {
							this.$refs.uToast.show({
								title: '获取信息错误',
								type: 'error'
							})
							return
						}
						if (res.data.data.length === 0) {
							that.infoshow = false
						} else {
							that.movies = res.data.data
							if (that.filmId != "") {
								for (var i = 0; i < that.movies.length; i++) {
									if (that.movies[i].filmId == that.filmId) {
										that.params.image = that.movies[i].smallPhoto
										that.infos = that.movies[i]
										that.current = i
										uni.setNavigationBarTitle({
											title: that.infos.name
										})
										break
									}
								}
							} else {
								that.params.image = this.movies[0].smallPhoto
								that.infos = this.movies[0]
								uni.setNavigationBarTitle({
									title: that.infos.name
								})
							}
							that.infoshow = true
							this.initdata()

						}

					},
					complete() {
						uni.stopPullDownRefresh()
					}
				})
			},
			clickimg(index) {
				this.current = index;
			},
			change(index) {
				this.currents = 0;
				this.bkshow = false;
				let that = this;
				this.params.image = this.movies[index].smallPhoto
				this.infos = this.movies[index]
				uni.setNavigationBarTitle({
					title: this.infos.name
				})
				setTimeout(function() {
					// 这里就是处理的事件
					that.bkshow = true;
				}, 430);
				that.list = []
				that.initdata()
				// this.getjh(that.list[0].key);
			}
		}
	}
</script>

<style lang="scss">
	.infoa {
		text-align: center;
		margin-top: 20rpx;
		width: 90%;
		margin: 0 auto;
	}

	.cssk {
		position: absolute;
		margin-top: -283rpx;
		margin-left: 280rpx;
		z-index: 98;
		width: 194rpx;
		height: 265rpx;
		border: 1px solid #FFFFFF;
		z-index: 999;
	}

	.cssshape {
		position: absolute;
		margin-top: -15rpx;
		margin-left: 365rpx;
		z-index: 999;
		display: inline-block;
		width: 0;
		height: 0;
		border-left: 5px solid transparent;
		border-right: 5px solid transparent;
		border-bottom: 8px solid #ffffff;

	}

	.box {
		display: inline-block;
		width: 140rpx;
		height: 220rpx;
		background: #0062CC;
		margin-right: 30upx;
	}

	.scroll-view_H {
		width: 100%;
		overflow: hidden;
		white-space: nowrap;
	}

	.sx {
		width: 0px;
		height: 70rpx;
		border: 1px solid #707070;
		opacity: 0.3;
		margin-top: 10rpx;
	}

	.hide {
		display: -webkit-box;
		/*设置为弹性盒子*/
		-webkit-line-clamp: 1;
		/*最多显示1行*/
		overflow: hidden;
		/*超出隐藏*/
		text-overflow: ellipsis;
		/*超出显示为省略号*/
		-webkit-box-orient: vertical;
		
		/* 从上向下垂直排列子元素。 */

	}
</style>
